
package utils;

import generalArchitecture.ComputeBox;

import org.eclipse.emf.common.util.EList;

import processorUtilizationNB.ProcessorUtilisationNB;
import processorUtilizationNB.ProcessorUtilizationNBFactory;
import technicRMLL73.TechnicRMLL73;
import technicRMLL73.TechnicRMLL73Factory;
import technic_RM_ResponseTimeNB.ResponseTimeRMNB;
import technic_RM_ResponseTimeNB.Technic_RM_ResponseTimeNBFactory;
import basicModelType1.BasicModelType1;
import basicModelType1.BasicModelType1Factory;
import boundRMLL73.BoundRMLL73;
import boundRMLL73.BoundRMLL73Factory;


public class UtilsModelInstance {

	public static processorUtilizationNB.ProcessorUtilisationNB createPUNB (EList<Integer> period, EList<Integer> wcet) {
		
		/**/
		processorUtilizationNB.ProcessorUtilisationNB pu = ProcessorUtilizationNBFactory.eINSTANCE.createProcessorUtilisationNB();
		
		/**/
		pu.setPeriods(period);
		pu.setWcets(wcet);
		
		return pu;
		
	} // createPUNB
	
	public static BoundRMLL73 createBound_RM_LL73 (int nb_tasks) {
		
		/**/
		BoundRMLL73 bound = BoundRMLL73Factory.eINSTANCE.createBoundRMLL73();
		
		/**/
		bound.setNb_Tasks(nb_tasks);
		
		return bound;
		
	} // createBound_RM_LL73
	
	public static TechnicRMLL73 createTechnicRMLL73 (BoundRMLL73 b, ProcessorUtilisationNB u) {
		
		/**/
		TechnicRMLL73 t = TechnicRMLL73Factory.eINSTANCE.createTechnicRMLL73();
		
		/**/
		t.setBoundLL73(b);
		t.setPU(u);
		
		/**/
		
		return t;
				
	} // createTechnicRMLL73
	
	public static BasicModelType1 createLightModel_1 (int scheduler , EList< String> l_ids , EList< Integer> l_wcet, EList< Integer> l_period, EList<Integer> l_deadline) {
		
		/**/
		BasicModelType1 lm1 = BasicModelType1Factory.eINSTANCE.createBasicModelType1();
		
		/**/
		lm1.setScheduler(scheduler);
		lm1.setPeriods(l_period);
		lm1.setWcets(l_wcet);
		lm1.setDeadlines(l_deadline);
		lm1.setIds(l_ids);
		
		return lm1;

	} // createLightModel_1

	public static ResponseTimeRMNB createResponseTime_RM_NB (EList< String> l_ids , EList< Integer> l_wcet, EList< Integer> l_period, EList<Integer> l_deadline) {
		
		/**/
		ResponseTimeRMNB rt = Technic_RM_ResponseTimeNBFactory.eINSTANCE.createResponseTimeRMNB();
		
		/**/
		rt.setPeriods(l_period);
		rt.setWcets(l_wcet);
		rt.setDeadlines(l_deadline);
		rt.setIds(l_ids);
		
		return rt; 
		
	} // createResponseTime_RM_NB
	
	public static void linkComputeBox (ComputeBox current, ComputeBox next, boolean exists) {
		
		if (!exists) {
			
			/* Set Root attribute & add to Root list*/
			next.setRoot(current.getRoot());
			next.getRoot().getComputeBoxes().add(next);
		}

		/* Graph paths */
		current.getNext().add(next);
		next.getPrevious().add(current);
		
	} // linkComputeBox () 
	
	
	public static <T extends ComputeBox> ComputeBox lookForComputeBox (ComputeBox current, Class<T> className) {
		
		/**/
		for (ComputeBox box : current.getRoot().getComputeBoxes()) {
		
			if (box.getClass() == className) {
				return box;
			}				
		}
		
		return null;
		
	} // lookForComputeBox ()
	
} // class UtilsModelInstance